#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QMouseEvent>
#include <QPoint>
#include "scene.h"
#include "shadermanager.h"
#include <QGLWidget>

enum VIEWPORT_TYPE { TOP_VIEW = 0, BOTTOM_VIEW, LEFT_VIEW, RIGHT_VIEW, FRONT_VIEW, BACK_VIEW };


class GLWidget : public QGLWidget
{
    Q_OBJECT
public:
    explicit GLWidget(VIEWPORT_TYPE type = TOP_VIEW, QWidget *parent = 0);
    void initializeGL();
    void paintGL();
    void resizeGL(int width, int height);
    void set_scene(Scene *scene);
public slots:
    void setXRotation(int angle);
    void setYRotation(int angle);
    void setZRotation(int angle);

signals:
    void xRotationChanged(int angle);
    void yRotationChanged(int angle);
    void zRotationChanged(int angle);
protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void keyPressEvent(QKeyEvent *event);
private:
    void normalizeAngle(int *angle);
    VIEWPORT_TYPE m_type;
    Scene *m_scene;
    Renderer renderer;

    int xRot;
    int yRot;
    int zRot;
    QPoint lastPos;
    glm::vec3 m_position;
    float m_camera_speed;
    ShaderManager m_shaders;
};

#endif // GLWIDGET_H
